package top.xiangqifu.springboot2.user.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.xiangqifu.springboot2.user.base.BaseDataResult;
import top.xiangqifu.springboot2.user.base.BaseResult;
import top.xiangqifu.springboot2.user.entity.TbUser;
import top.xiangqifu.springboot2.user.service.AuthService;
import top.xiangqifu.springboot2.user.vo.UserInfo;


@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
@Api(tags = "用户信息相关接口")
public class AuthController {
    private final AuthService authService;

    @ApiOperation(value ="用户登录",notes = "用户登录功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "用户账号",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "password",value = "用户密码",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "token",value = "用户token",dataTypeClass = String.class ,required = true),
    })
    @PostMapping("")
    public BaseResult login(@RequestBody TbUser tbUser) {
        return authService.login(tbUser);
    }

    @ApiOperation(value ="登录用户信息",notes = "获取登录用户信息功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "用户token",dataTypeClass = String.class ,required = true),
    })
    @GetMapping("")
    public BaseDataResult<UserInfo> getUserInfo() {
        return authService.getLoginUser();
    }


}
